package com.iyoudoock.citymine.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.iyoudoock.citymine.R;
import com.iyoudoock.citymine.bean.BlacklistBean;
import com.kvin.toolkit.adapter.BasicAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Kvin on 2017/6/21.
 */
public class BlacklistAdapter extends BasicAdapter<BlacklistAdapter.ViewHolder, BlacklistBean> {

    public BlacklistAdapter(List<BlacklistBean> list, Context context) {
        super(list, context);
    }

    @Override
    protected View getConvertView(LayoutInflater inflater, ViewGroup viewGroup, Context context, List<BlacklistBean> list, int i) {
        return inflater.inflate(R.layout.adapter_blacklist, viewGroup, false);
    }

    @Override
    protected ViewHolder initView(View view, ViewGroup viewGroup, Context context) {
        return new ViewHolder(view);
    }

    @Override
    protected void bindData(ViewHolder vh, int i, List<BlacklistBean> list, Context context) {
        BlacklistBean bean = list.get(i);
        if (!TextUtils.isEmpty(bean.getHeadImage())) {
            ImageLoader.getInstance().displayImage(bean.getHeadImage(), vh.avatarIv);
        }
        vh.recyclerNoTv.setText(bean.getUsername() + "(" + bean.getNo() + ")");

        vh.descTv.setText("回收" + bean.getRecycleTimes() + "次  好评:" + bean.getScore());
        vh.removeBtn.setTag(i);
        vh.removeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnChildClickListener != null)
                    mOnChildClickListener.onClick(v, (Integer) v.getTag());
            }
        });

    }

    static class ViewHolder extends BasicAdapter.ViewHolder {
        ImageView avatarIv;
        TextView recyclerNoTv;
        TextView descTv;
        Button removeBtn;

        public ViewHolder(View v) {
            super(v);
            this.avatarIv = (ImageView) v.findViewById(R.id.avatar_iv);
            this.recyclerNoTv = (TextView) v.findViewById(R.id.recycler_no_tv);
            this.descTv = (TextView) v.findViewById(R.id.desc_tv);
            this.removeBtn = (Button) v.findViewById(R.id.remove_btn);
        }
    }
}
